<%@ page import="admin.Connectmysql" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2025/6/15
  Time: 12:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

</head>
<body>
<%
    response.setCharacterEncoding("UTF-8");

int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String email = request.getParameter("email");
String gender = request.getParameter("gender");
String password = request.getParameter("password");
    Connectmysql cmysql = new Connectmysql(
            "jdbc:mysql://localhost:3306/exam1",
            "root",
            "root",
            "com.mysql.cj.jdbc.Driver");
    try {
        if(cmysql.open()){

            ResultSet rst= cmysql.executeSql(
                    "SELECT id FROM teacher WHERE id = ?;",
                    new Object[]{id}
            );
            if(rst!=null&&rst.next()){
                // ID已存在，返回错误信息
                System.out.println("id存在");
            }else{
               int rst2 = cmysql.executeSqlUpdate("INSERT INTO teacher (id,username,name, gender, email, password,status) VALUES (?, ?,?, ?, ?, ?,?);"
                       ,new Object[]{id,name,name,gender,email,password,"active"}
               );
               if(rst2>0){
                    //添加成功
                   System.out.println("添加成功");
               }else {
                   //添加失败
               }


                }



//



            rst.close();

        }
    } catch (ClassNotFoundException f) {
        f.printStackTrace();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }




%>
</body>
</html>
